package com.ad.pet.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.ad.pet.Logger;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.app.account.CommonWebActitivity;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.ui.DialogUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.structure.events.Events;
import com.ad.pet.common.structure.events.RxBus;
import com.ad.pet.common.structure.ui.activity.BaseActivity;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.PayResult;
import com.ad.pet.models.remote.WebTitle;
import com.alipay.sdk.app.PayTask;
import com.just.agentweb.AgentWeb;
import com.tbruyelle.rxpermissions.RxPermissions;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;

import java.util.Map;

import rx.functions.Action1;

//import com.jiuhe.handi.wxapi.WXPayUtils;

/**
 * Created by SEELE on 2018/3/26.
 */

public class AndroidInterface {
    static final int SDK_PAY_FLAG = 1;
    private Handler deliver = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG:
//                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
//                    /**
//                     对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
//                     */
//                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
//                    String resultStatus = payResult.getResultStatus();
//                    String notifyUrl = payResult.getNotifyUrl();
//                    // 判断resultStatus 为9000则代表支付成功
//                    if (TextUtils.equals(resultStatus, "9000")) {
////                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
////                        ToastUtil.getToastUtil().showShort(context.getString(R.string.pay_success));
//
//                        RxBus.getDefault().post(new Events.PayStatusCallback(notifyUrl, "alipay_app", resultInfo));
//                    } else {//支付失败
////                        ToastUtil.getToastUtil().showShort(context.getString(R.string.pay_failed));
//                        RxBus.getDefault().post("login_success");
//                    }
//                    break;
            }
        }
    };
    private AgentWeb agent;
    private Context context;

    public AndroidInterface(AgentWeb agent, Context context) {
        this.agent = agent;
        this.context = context;
    }


    @JavascriptInterface
    public void storage(final String url, final String title) {//个人中心--已入库


        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);

            }
        });

    }

    @JavascriptInterface
    public void waitPayment(final String url, final String title) {//待支付


        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);

            }
        });

    }

    @JavascriptInterface
    public void purchasing(final String url, final String title) {


        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);

            }
        });

    }

    @JavascriptInterface
    public void packageOrder(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void packageDelivery(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void packageHarvested(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void packageProblem(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void fillInvoice(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void customerDelivered(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void inStorage(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void packaged(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void collection(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void helping(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void financial(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void service(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void info(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_HOME);
            }
        });
    }

    @JavascriptInterface
    public void coupons(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void freight(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void sendingLimit(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void allOrders(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void allPackage(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void allTransfer(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void userPay(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void linkUrl(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void problemOrders(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }


    @JavascriptInterface
    public void logout() {
        MobclickAgent.onProfileSignOff();
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("login_out");
            }
        });
    }

    @JavascriptInterface
    public void checkOrder(final String url) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessCartReload");
                Navigation.goCommonWebView((Activity) context, context.getString(R.string.my_order), url, false);
            }
        });
    }

    @JavascriptInterface
    public void goIndex(int index) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessCartReload");
                if (context instanceof MainActivity) {
                    ((MainActivity) context).mTabLayout.setCurrentTab(0);
                }
                if (context instanceof CommonWebActitivity) {
                    Intent intent = new Intent();
                    ((CommonWebActitivity) context).setResult(Activity.RESULT_OK, intent);
                    intent.putExtra("goHome", 1);
                    ((CommonWebActitivity) context).finish();
                }

            }
        });
    }

    @JavascriptInterface
    public void baseInfo(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void myAddress(final String url, final String title) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
//                Navigation.goCommonWebView((Activity) context, title, url, false);
            }
        });
    }

    @JavascriptInterface
    public void shoppingCart(final String url, final String title) {//购物车
        deliver.post(new Runnable() {
            @Override
            public void run() {
                if (!((BaseActivity) context).hasLogin()) {
                    Navigation.goLogin((Activity) context, 79, 0);
                    return;
                }
                RxBus.getDefault().post("accountCheckSuccessCartReload");
                ((Activity) context).setResult(Activity.RESULT_OK, new Intent());
                ((Activity) context).finish();
            }
        });
    }

    @JavascriptInterface
    public void goIndexHome(final int url) {//去首页
        deliver.post(new Runnable() {
            @Override
            public void run() {
                ((MainActivity) context).mTabLayout.setCurrentTab(0);
            }
        });
    }

    @JavascriptInterface
    public void cartName(final String url) {//购物车进入商品详情页
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, context.getString(R.string.good_detail), url, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void productDetail(final String url) {//商品详情
        deliver.post(new Runnable() {
            @Override
            public void run() {
                String mUrl = "";
                if (url.contains(context.getString(R.string.ip_host))) {
                    mUrl = url.replace(context.getString(R.string.ip_host), "");
                } else {
                    mUrl = url;
                }
                Navigation.goCommonWebView((Activity) context, context.getString(R.string.good_detail), mUrl, false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @JavascriptInterface
    public void goCartAnd(final String url) {//去购物车
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessCartReload");
                ((Activity) context).setResult(Activity.RESULT_OK, new Intent());
                ((Activity) context).finish();
            }
        });
    }

    @JavascriptInterface
    public void goHome() {//去首页
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent();
                intent.putExtra("goHome", 1);
                ((Activity) context).setResult(Activity.RESULT_OK, intent);
                ((Activity) context).finish();
            }
        });
    }

    @JavascriptInterface
    public void pay_to_account(String arg) {//购物车充值去个人中心
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessAccount");
                if (context instanceof CommonWebActitivity) {
                    Intent intent = new Intent();
                    intent.putExtra("goHome", 3);
                    ((Activity) context).setResult(Activity.RESULT_OK, intent);
                    ((Activity) context).finish();
                }
                if (context instanceof MainActivity) {
                    ((MainActivity) context).mTabLayout.setCurrentTab(3);
                }
            }
        });
    }

    @JavascriptInterface
    public void pay_to_index(String arg) {//购物车充值去首页逛逛
        deliver.post(new Runnable() {
            @Override
            public void run() {
                if (context instanceof CommonWebActitivity) {
                    RxBus.getDefault().post("accountCheckSuccessCartReload");
                    Intent intent = new Intent();
                    intent.putExtra("goHome", 1);
                    ((Activity) context).setResult(MainActivity.RESULT_OK, intent);
                    ((Activity) context).finish();

                }
                if (context instanceof MainActivity) {
                    ((MainActivity) context).mTabLayout.setCurrentTab(0);
                }
            }
        });
    }

    @JavascriptInterface
    public void pay_to_account_center(String arg) {//个人中心充值去个人中心
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessAccount");
                if (context instanceof CommonWebActitivity) {
                    Intent intent = new Intent();
                    intent.putExtra("goHome", 3);
                    ((Activity) context).setResult(Activity.RESULT_OK, intent);
                    ((Activity) context).finish();
                }
                if (context instanceof MainActivity) {
                    ((MainActivity) context).mTabLayout.setCurrentTab(3);
                }
            }
        });
    }

    @JavascriptInterface
    public void pay_to_index_center(String arg) {//个人中心充值去首页逛逛
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessCartReload");
                if (context instanceof CommonWebActitivity) {
                    Intent intent = new Intent();
                    intent.putExtra("goHome", 1);
                    ((Activity) context).setResult(MainActivity.RESULT_OK, intent);
                    ((Activity) context).finish();
                }
                if (context instanceof MainActivity) {
                    ((MainActivity) context).mTabLayout.setCurrentTab(0);
                }
            }
        });
    }

    @JavascriptInterface
    public void goIndex() {//详情页抓不到，重定向到首页
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent();
                intent.putExtra("goHome", 1);
                ((Activity) context).setResult(Activity.RESULT_OK, intent);
                ((Activity) context).finish();

            }
        });
    }

    @JavascriptInterface
    public void collectList(final String arg) {//收藏商品点击
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Navigation.goCommonWebView((Activity) context, context.getString(R.string.good_detail), arg, false, MainActivity.REQUEST_GO_MALL);

            }
        });
    }

    @JavascriptInterface
    public void toMyAccount(String arg) {//打包入库付钱去个人中心
        deliver.post(new Runnable() {
            @Override
            public void run() {
                RxBus.getDefault().post("accountCheckSuccessAccount");
                if (context instanceof CommonWebActitivity) {
                    Intent intent = new Intent();
                    intent.putExtra("goHome", 3);
                    ((Activity) context).setResult(Activity.RESULT_OK, intent);
                    ((Activity) context).finish();
                }
            }
        });
    }

    @JavascriptInterface
    public void goIndex(String arg) {//活动页
        deliver.post(new Runnable() {
            @Override
            public void run() {


            }
        });
    }

    @JavascriptInterface
    public void alipayment_app(final String arg1, final String arg2) {//支付宝原生
        deliver.post(new Runnable() {
            @Override
            public void run() {
                Logger.a("alipay:", arg1, arg2);
                final String orderInfo = arg1;   // 订单信息

                Runnable payRunnable = new Runnable() {

                    @Override
                    public void run() {
                        PayTask alipay = new PayTask((Activity) context);
                        Map<String, String> result = alipay.payV2(orderInfo, false);
                        result.put("notify_url", arg2);
                        Message msg = new Message();
                        msg.what = SDK_PAY_FLAG;
                        msg.obj = result;
                        deliver.sendMessage(msg);
                    }
                };
                // 必须异步调用
                Thread payThread = new Thread(payRunnable);
                payThread.start();
            }
        });
    }

    @JavascriptInterface
    public void weixinpayment_app(final String arg1, final String arg2, final String arg3, final String arg4, final String arg5, final String arg6, final String arg7) {//活动页
//        deliver.post(new Runnable() {
//            @Override
//            public void run() {
//                Logger.a("weixinpayment_app", arg1, arg2, arg3, arg4, arg5, arg6, arg7);
//                WXPayUtils wxPayUtil = new WXPayUtils(context);
//                if (wxPayUtil.isWxAppInstalledAndSupported()) {
//                    Wxpay wxpay = new Wxpay(Constant.APP_ID, arg4, arg5, arg2, arg7, arg3, arg6, arg1);
//                    wxPayUtil.doPay(new Gson().toJson(wxpay));
//                } else {
//                    ToastUtil.getToastUtil().showShort(context.getString(R.string.not_wx_tips));
//                }
//            }
//        });
    }

    @JavascriptInterface
    public void login() {
        deliver.post(new Runnable() {
            @Override
            public void run() {


                Navigation.goLogin((Activity) context, -1, -1);
                ((Activity) context).finish();


            }
        });
    }

    @JavascriptInterface
    public void to_call(final String phoneNumber) {
        deliver.post(new Runnable() {
            @Override
            public void run() {
                DialogUtil.createDialog((Activity) context, context.getString(R.string.is_call), phoneNumber, true, ((Activity) context).getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }, context.getString(R.string.confirm), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        RxPermissions rxPermissions = new RxPermissions((Activity) context);
                        rxPermissions.request(Manifest.permission.CALL_PHONE).subscribe(new Action1<Boolean>() {
                            @Override
                            public void call(Boolean aBoolean) {
                                if (aBoolean) {
                                    Intent intent = new Intent();
                                    intent.setAction("android.intent.action.CALL");
//                                    intent.addCategory("android.intent.category.DEFAULT");
                                    String pn = phoneNumber;
                                    Logger.e("tel:" + pn);
                                    intent.setData(Uri.parse("tel:" + pn));
                                    ((Activity) context).startActivity(intent);//方法内部自动添加android.intent.category.DEFAULT
                                } else {
                                    DialogUtil.createDialogNoShow((Activity) context, context.getString(R.string.tips), context.getString(R.string.refuse_read_call), false, context.getString(R.string.cancel),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                }
                                            }, context.getString(R.string.go_set), new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                    Uri packageURI = Uri.parse("package:" + context.getPackageName());
                                                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
                                                    context.startActivity(intent);
                                                }
                                            }).show();
                                }
                            }
                        });
                    }
                }).show();

            }
        });
    }

    @JavascriptInterface
    public void share(String title, String content, String img, String url) {
        ShareBoardConfig mBoardConfig = new ShareBoardConfig();
        mBoardConfig.setIndicatorVisibility(false);

        final UMWeb web = new UMWeb(url);
        web.setTitle(title);//标题
        Logger.e(url);
        if (url.startsWith("//")) {
            url = "http:" + url;

        }
        Logger.e("imageShare_url:" + url);
        UMImage umImage = new UMImage(context, url);
        web.setThumb(umImage);  //缩略图
        web.setDescription(title);//描述
        new ShareAction((Activity) context)
                .withMedia(web)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .setCallback(new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                        ToastUtil.getToastUtil().showShort(throwable.getMessage());
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {

                    }
                })
                .open(mBoardConfig);
    }


    @JavascriptInterface
    public void getCouper(String url, String title) {
        Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
//        ((Activity)context).finish();
    }

    @JavascriptInterface
    public void tomyCoupon(String url, String title) {
        Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
    }


    /**
     * 专区进入详情页
     */
    @JavascriptInterface
    public void featureProduct(String itemid, String url, String title) {
        Navigation.goCommonWebView((Activity) context, context.getString(R.string.good_detail), url, false, MainActivity.REQUEST_GO_MALL);
    }


//

    /**
     * 专区进入店铺页
     */
    @JavascriptInterface
    public void enterPackage(String url, String title) {
        Navigation.goCommonWebView((Activity) context, title, url, false, MainActivity.REQUEST_GO_MALL);
    }

    @JavascriptInterface
    public void orderProduct(String url) {
        Navigation.goCommonWebView((Activity) context, context.getString(R.string.good_detail), url, false, MainActivity.REQUEST_GO_MALL);
    }

    @JavascriptInterface
    public void changeTitle(String title) {
        WebTitle webTitle = new WebTitle(title);
        RxBus.getDefault().post(webTitle);
        Logger.e(webTitle.getTitle());
    }

    @JavascriptInterface
    public void search(String name) {
        Navigation.goSerachEnd((Activity) context, name, MainActivity.REQUEST_GO_MALL, "", "");
    }

    @JavascriptInterface
    public void category(String first, String category, String type) {

        int cate = Integer.valueOf(type);

        Events.TypeChose typeChose = new Events.TypeChose(first, category, cate);

        RxBus.getDefault().post(typeChose);
        ((Activity) context).finish();


    }

    @JavascriptInterface
    public void goDetail(String id) {

        Navigation.goGoodDetail((Activity) context, MainActivity.REQUEST_GO_MALL, id);


    }

    @JavascriptInterface
    public void goCoupons(String url) {

        Navigation.goCommonWebView(context, context.getString(R.string.conpuons), url);

    }

    @JavascriptInterface
    public void MonthcardList(String url) {
        if (TextUtils.isEmpty(SpUtil.getInstance().getString(Constant.ACCESS_TOKEN))){
            Navigation.goLogin((Activity) context,1,1);
            return;
        }
        PayResult payResult = new PayResult();
        payResult.setOrder_id(url);
        RxBus.getDefault().post(payResult);
    }

    @JavascriptInterface
    public void CouponList(String order_id) {
        if (TextUtils.isEmpty(SpUtil.getInstance().getString(Constant.ACCESS_TOKEN))){
            Navigation.goLogin((Activity) context,1,1);
            return;
        }
        PayResult payResult = new PayResult();
        payResult.setOrder_id(order_id);
        RxBus.getDefault().post(payResult);

    }
    @JavascriptInterface
    public void yuepay(String order_id) {

        PayResult payResult = new PayResult();
        payResult.setPayType("5");
        payResult.setOrder_id(order_id);
        RxBus.getDefault().post(payResult);

    }
    @JavascriptInterface
    public void wchatpay(String order_id) {

        PayResult payResult = new PayResult();
        payResult.setPayType("1");
        payResult.setOrder_id(order_id);
        RxBus.getDefault().post(payResult);

    }
    @JavascriptInterface
    public void alipay(String order_id) {

        PayResult payResult = new PayResult();
        payResult.setPayType("2");
        payResult.setOrder_id(order_id);
        RxBus.getDefault().post(payResult);

    }
    @JavascriptInterface
    public void goBack() {
        ((Activity) context).finish();
    }


    @JavascriptInterface
    public void jumpUserCenter() {
        if (TextUtils.isEmpty(SpUtil.getInstance().getString(Constant.ACCESS_TOKEN))){
            Navigation.goLogin((Activity) context,1,1);
            return;
        }
        Intent intent = new Intent();
        ((CommonWebActitivity) context).setResult(Activity.RESULT_OK, intent);
        intent.putExtra("goHome", 3);
        ((CommonWebActitivity) context).finish();
    }

//    货源手机端顶部搜索方法名：searchGoods();
//    货源手机端10大分类方法名：offerSearch(url,tit);
//    货源手机端商品详情点击方法名：offerItemDetail(url);

//    包裹未付款 packageOrder
//    包裹发货中 packageDelivery
//    包裹已收货 packageHarvested
//    包裹异常   packageProblem
//    填写发货单 fillInvoice
//    客户已发货 customerDelivered
//    客户已入库 inStorage
//    已打包     packaged
//    我的收藏   collection
//    帮助中心   helping
//    财务管理   financial
//    客户服务   service
//    个人信息   info
//    我的优惠   coupons
//    运费估算   freight
//    寄送限制   sendingLimit
//    查看全部订单 allOrder
//    查看全部包裹 allPackage
//    查看全部转运 allTransfer
//    立即充值     userPay
//2018/3/26 13:19:25
//    吴熠 2018/3/26 13:19:25
//    收获地址 myAddress
//    基本资料 baseInfo
//    修改密码 changepwd
//    邮件提醒 emailTips

}
